//
// Created by Semir on 2020/5/7.
//

#include <iostream>
#include <vector>

using namespace std;

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode* next) : val(x), next(next) {}
};

vector<int> printListFromTailToHead(ListNode* head) {
    vector<int> res;
    if (head == nullptr) {
        return res;
    }
    auto* auxHead = new ListNode(0);
    ListNode* node = head;
    while (node) {
        auto* newNode = new ListNode(node->val);
        newNode->next = auxHead->next;
        auxHead->next = newNode;
        node = node->next;
    }
    node = auxHead->next;
    while (node) {
        res.emplace_back(node->val);
        node = node->next;
    }
    return res;
}

void test() {
    auto* node5 = new ListNode(6);
    auto* node4 = new ListNode(5, node5);
    auto* node3 = new ListNode(4, node4);
    auto* node2 = new ListNode(3, node3);
    auto* node1 = new ListNode(2, node2);
    vector<int> res = printListFromTailToHead(node1);
    cout << res.size() << endl;
}

int main() {
    test();
    return 0;
}